using System.Web.Http;
using System.Web.Routing;
using Microsoft.AspNet.FriendlyUrls;

namespace Medora.Web.Configs
{
    public static class RouteConfig
    {
        /// <summary>
        /// The controller only
        /// </summary>
        public static string ControllerOnly = "ApiControllerOnly";

        /// <summary>
        /// The controller and id
        /// </summary>
        public static string ControllerAndId = "ApiControllerAndGuid";

        /// <summary>
        /// The controller action
        /// </summary>
        public static string ControllerAction = "ApiControllerAction";

        /// <summary>
        /// The controller action and id
        /// </summary>
        public static string ControllerActionAndId = "ApiControllerActionAndId";

        public static void RegisterRoutes(RouteCollection routes)
        {

            routes.MapHttpRoute(
                name: ControllerOnly,
                routeTemplate: "api/{controller}",
                defaults: new {id = RouteParameter.Optional}
                );

            routes.MapHttpRoute(
                name: ControllerAndId,
                routeTemplate: "api/{controller}/{id}",
                constraints: new {id = @"^[0-9a-f]{32}$"}, // id must be guid
                defaults: new {id = RouteParameter.Optional}
                );
            routes.MapHttpRoute(
                name: ControllerAction,
                routeTemplate: "api/{controller}/{action}"
                );

            routes.MapHttpRoute(
                name: ControllerActionAndId,
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new {id = RouteParameter.Optional}
                );

            //routes.MapPageRoute("FormByNameRoute","FormTestPage/","~/FormTest.aspx");
           // routes.MapPageRoute("FormByNameRouteWithId", "{action}/{id}", "~/Pages/{action}.aspx");
            routes.MapPageRoute(routeName: "FormByNameRoute",
                                routeUrl: "Form/{name}/{*id}",
                                physicalFile: "~/Pages/{name}.aspx"
                );

            routes.MapPageRoute(
                "FormsList",
                "Forms",
                "~/Default.aspx"
            );

            routes.MapPageRoute(
                "ModulePage",
                "{name}",
                "~/Pages/{name}.aspx"
            );
            

            routes.EnableFriendlyUrls();
        }
    }
}
